<template>
    <div>
      <!-- <a-button type="primary" @click="showModal">Open Modal with customized footer</a-button> -->
      <a-modal v-model:visible="visible" @ok="handleOk" class="modal" :bodyStyle="{height:150+'px'}" >
        <template #footer>
          <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
        </template>
        <a-row></a-row>
        <a-row>
            <a-col :span="4"></a-col>
            <a-col :span="5">
                <h3>保管人：</h3>
            </a-col>
            <a-col :span="6">
                <a-input v-model:value="keeperValue" placeholder=""></a-input>
            </a-col>
        </a-row>
      </a-modal>
    </div>
</template>
<script setup>
import { ref } from 'vue';
import request from '@/utils/request'

const visible = ref(false);
const keeperValue = ref('')

const props=defineProps(['selectedRecord'])
const emit=defineEmits(['loadData'])

const showModal = () => {
  keeperValue.value=''
  visible.value = true;
};

const handleOk = async() => {
  console.log(props.selectedRecord)
  if(props.selectedRecord.length===1){
    const result=await request({
      url:'/tools/keeper',
      method:'post',
      data:{
        id:props.selectedRecord[0].id,
        keeper:keeperValue.value
      }
    })
    // console.log(result)
    const obj={
      orgName:props.selectedRecord[0].orgName,
      categoryName:props.selectedRecord[0].name
    }
    emit('loadData',obj)
    keeperValue.value=''
    // console.log(result)
  }
  else{
    const list=ref([])
    for(var i=0;i<props.selectedRecord.length;i++){
      const obj={
        org_name:props.selectedRecord[i].orgName,
        name:props.selectedRecord[i].name,
        id:props.selectedRecord[i].id
      }
      list.value.push(obj)
    }
    console.log(list.value)
    const result=await request({
      url:'/tools/keepers',
      method:'post',
      data:{
        list:list.value,
        keeper:keeperValue.value
      }
    })
    console.log(result)
  }
  const obj={
      orgName:props.selectedRecord[0].orgName,
      categoryName:props.selectedRecord[0].name
    }
  emit('loadData',obj)
  visible.value = false;
};

defineExpose({
  showModal,
})
</script>
<style scoped>
.modal{
    height: 600px;
}
h3{
    font-weight: 900;
}
</style>
